﻿using System;
using System.Windows.Media.Media3D;
using Perspective.Wpf3D.Primitives;
using Perspective.Wpf3D.Sculptors;
using System.Windows;

namespace Perspective.Wpf3D.Shapes
{
    /// <summary>
    /// 同心多边形
    /// A 3D flat concentric polygon element.
    /// Default radius is 1.0.
    /// </summary>
    public class ConcentricPolygon3D : PolygonalElement3D
    {
         #region Constructors
        /// <summary>
        /// Initializes a new instance of Concentric ConcentricPolygon3D.
        /// </summary>
        public ConcentricPolygon3D()
        {
        }
        #endregion

        #region Properties

        #region OuterRadius 外圆半径
        /// <summary>
        /// 外圆半径
        /// Gets or sets the concentric polygon  outer circle radius.
        /// Default value is 1.0.
        /// </summary>
        public double OuterRadius
        {
            get { return (double)GetValue(OuterRadiusProperty); }
            set { SetValue(OuterRadiusProperty, value); }
        }

        /// <summary>
        /// Identifies the outer circle radius dependency property.
        /// </summary>
        public static readonly DependencyProperty OuterRadiusProperty =
            DependencyProperty.Register(
                "OuterRadius",
                typeof(double),
                typeof(ConcentricPolygon3D),
                new UIPropertyMetadata(
                    ConcentricPolygonSculptor.DefaultOuterCircleRadius, 
                    VisualPropertyChanged),
                    PositiveDoubleValidateValue);
        #endregion

        #region InnerRadius 内圆半径
        /// <summary>
        /// 内圆半径
        /// Gets or sets the concentric polygon inner circle radius.
        /// Default value is 1.0.
        /// </summary>
        public double InnerRadius
        {
            get { return (double)GetValue(InnerRadiusProperty); }
            set { SetValue(InnerRadiusProperty, value); }
        }

        /// <summary>
        /// Identifies the inner circle radius dependency property.
        /// </summary>
        public static readonly DependencyProperty InnerRadiusProperty =
            DependencyProperty.Register(
                "InnerRadius",
                typeof(double),
                typeof(ConcentricPolygon3D),
                new UIPropertyMetadata(
                    ConcentricPolygonSculptor.DefaultInnerCircleRadius,
                    VisualPropertyChanged),
                    PositiveDoubleValidateValue);
        #endregion

        #endregion

        /// <summary>
        /// Called by UIElement3D.InvalidateModel() to update the 3D model.
        /// </summary>
        protected override void OnUpdateModel()
        {
            Sculptor = new ConcentricPolygonSculptor(OuterRadius,InnerRadius, SideCount, InitialAngle, RoundingRate);
            base.OnUpdateModel();
        }
    }
}
